package com.eastfair.visitor.controller;

import com.eastfair.visitor.dto.*;
import com.eastfair.visitor.entity.AuditSettings;
import com.eastfair.visitor.service.AuditSettingsService;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.eastfair.boot.controller.SuperController;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.eastfair.echo.core.EchoService;
import com.eastfair.core.base.R;
import com.eastfair.visitor.vo.AuditSettingsVO;
import com.eastfair.visitor.vo.DepartmentVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import com.eastfair.annotation.annotation.security.PreAuth;

import com.eastfair.boot.request.PageParams;
import com.eastfair.core.context.ContextUtil;
import org.springframework.web.bind.annotation.RestController;


/**
 * <p>
 * 前端控制器
 * 审核设置表
 * </p>
 *
 * @author lyw
 * @date 2022-11-18
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/auditSettings")
@Api(value = "AuditSettings", tags = "审核设置表")
@PreAuth(replace = "visitor:auditSettings:")
public class AuditSettingsController extends SuperController<AuditSettingsService, Long, AuditSettings, AuditSettingsPageQuery, AuditSettingsSaveDTO, AuditSettingsUpdateDTO> {

    @Autowired
    private EchoService echoService;
    @Autowired
    private AuditSettingsService auditSettingsService;

    @Override
    public void handlerResult(IPage<AuditSettings> page) {
        // 想让返回值实现自动回显，请将此行代码打开
        // echoService.action(page);
    }
    /**
     * Excel导入后的操作
     *
     * @param list
     */
    @Override
    public R<Boolean> handlerImport(List<Map<String, String>> list){
        List<AuditSettings> auditSettingsList = list.stream().map((map) -> {
            AuditSettings auditSettings = AuditSettings.builder().build();
            //TODO 请在这里完成转换
            return auditSettings;
        }).collect(Collectors.toList());

        return R.success(baseService.saveBatch(auditSettingsList));
    }



    /**
     * 处理参数
     *
     * @param params 分页参数
     */
    @Override
    public void handlerQueryParams(PageParams<AuditSettingsPageQuery> params) {
        AuditSettingsPageQuery pageQuery = params.getModel();

    }

    /**
     * 审核开关列表
     *
     * @param params
     * @return
     */
    @ApiOperation(value = "审核开关列表")
    @PostMapping(value = "/queryAuditSettingsList")
    public R<IPage<AuditSettingsVO>> queryAuditSettingsList(@RequestBody PageParams<AuditSettingsPageQuery> params) {

        IPage<AuditSettingsVO> page = auditSettingsService.queryDepartmentList(params);
        return R.success(page);

    }

    /**
     * 审核开关列表
     *
     * @param auditSettingsPageQuery
     * @return
     */
    @ApiOperation(value = "审核开关列表")
    @PostMapping(value = "/getAuditSettingsList")
    public R<List<AuditSettingsVO>> getAuditSettingsList(@RequestBody AuditSettingsPageQuery auditSettingsPageQuery) {

        List<AuditSettingsVO> auditSettingsList = auditSettingsService.getAuditSettingsList(auditSettingsPageQuery);
        return R.success(auditSettingsList);

    }

    /**
     * 查询开关信息
     * @param
     * @return
     */
    @ApiOperation(value = "查询开关信息")
    @PostMapping(value = "/getAuditSettingsInfo")
    public R<AuditSettingsVO> getAuditSettingsInfo () {

        return R.success(auditSettingsService.getAuditSettingsInfo());
    }



    /**
     * 添加审核开关
     * @param auditSettingsSaveDTO
     * @return
     */
    @ApiOperation(value = "添加审核开关")
    @PostMapping(value = "/saveAuditSettingsInfo")
    public R<Boolean> saveAuditSettingsInfo (@RequestBody AuditSettingsSaveDTO auditSettingsSaveDTO) {

        return R.success(auditSettingsService.saveAuditSettingsInfo(auditSettingsSaveDTO));
    }

    /**
     * 修改审核开关
     *
     * @return
     */
    @ApiOperation(value = "修改审核开关")
    @PostMapping(value = "/updateAuditSettingsInfo")
    public R<Boolean> updateAuditSettingsInfo(@RequestBody AuditSettingsUpdateDTO auditSettingsUpdateDTO){

        return R.success(auditSettingsService.updateAuditSettingsInfo(auditSettingsUpdateDTO));
    }

    /**
     * 逻辑删除审核开关
     *
     * @return
     */
    @ApiOperation(value = "逻辑删除审核开关")
    @PostMapping(value = "/delAuditSettingsById")
    public R<Boolean> delAuditSettingsById(@RequestBody AuditSettingsUpdateDTO auditSettingsUpdateDTO) {
        return R.success(auditSettingsService.delAuditSettingsById(auditSettingsUpdateDTO));
    }


}
